



//
//  hometitlecell.swift
//  mywei
//
//  Created by myd on 15/12/20.
//  Copyright © 2015年 myd1. All rights reserved.
//

import UIKit

class hometitlecell: UITableViewCell {
    lazy var top1 : topview = topview()
    lazy var bom :bomview = bomview()
    lazy var textlab : UILabel = {
    let lab = UILabel()
        lab.numberOfLines = 0
        lab.textColor = UIColor.grayColor()
        lab.font = UIFont.systemFontOfSize(13)
        return lab
    }()
    lazy  var Collection : homecollectionview = homecollectionview()
    lazy var bomeview : bomview = bomview()
    var pre = NSLayoutConstraint()
    var prew = NSLayoutConstraint()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
//        pre.constant = CGFloat(arc4random_uniform(4))*90
        setpp()
    
        
    }
//    var idstr : String?
//    var bmiddle_pic : String?
//    var text : String?
//    var source : String?
//    var created_at : String?
//    var users : homeweiuser?
//    /// 转发数
//    var reposts_count = 0
//    /// 评论数
//    var comments_count = 0
//    /// 表态数
//    var attitudes_count = 0
//    var pic_urls : [[String : AnyObject]]?
    var weibodata : homeweimessage? {
        didSet
        {
            top1.data = weibodata
            textlab.text = weibodata?.text
            Collection.message=weibodata
            pre.constant = Collection.calcviewsize().height
            prew.constant = Collection.calcviewsize().width
        }
    }
    func setpp()
    {
       contentView.addSubview(bom)
         contentView.addSubview(top1)
        contentView.addSubview(textlab)
        contentView.addSubview(Collection)
        contentView.translatesAutoresizingMaskIntoConstraints = false
        textlab.translatesAutoresizingMaskIntoConstraints = false
         top1.translatesAutoresizingMaskIntoConstraints = false
        bom.translatesAutoresizingMaskIntoConstraints = false
        Collection.translatesAutoresizingMaskIntoConstraints = false
       contentView.addConstraint(NSLayoutConstraint(item: top1, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem:contentView , attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        contentView.addConstraint(NSLayoutConstraint(item: top1, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem:contentView , attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
        contentView.addConstraint(NSLayoutConstraint(item: top1, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem:contentView , attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
        contentView.addConstraint(NSLayoutConstraint(item: top1, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem:nil , attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 50))
        
        
        contentView.addConstraint(NSLayoutConstraint(item: textlab, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: top1, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 8))
          contentView.addConstraint(NSLayoutConstraint(item: textlab, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 350))
        contentView.addConstraint(NSLayoutConstraint(item: textlab, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 8))
//        contentView.addConstraint(NSLayoutConstraint(item: textlab, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -8))
        
//        addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem:contentView , attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
//        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: top1, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 8))
        
////        
//        contentView.addConstraint(NSLayoutConstraint(item: Collection, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: textlab, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 8))
//        
//        
//        prew = NSLayoutConstraint(item: Collection, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 290)
//        contentView.addConstraint(prew)
//        
//          pre = NSLayoutConstraint(item: Collection, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 290)
//        contentView.addConstraint(pre)
//        
//        contentView.addConstraint(NSLayoutConstraint(item: Collection, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 8))
        
        contentView.addConstraint(NSLayoutConstraint(item: bom, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: Collection, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant:8))
        contentView.addConstraint(NSLayoutConstraint(item: bom, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: textlab, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: -8))
        contentView.addConstraint(NSLayoutConstraint(item: bom, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: textlab, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 16))
        contentView.addConstraint(NSLayoutConstraint(item: bom, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 35))
        
        
        
        
        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: bom, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
//            pre .constant = (CGFloat(arc4random_uniform(4))*90)
    }
    
    
  
}
